//
//  BQYLAddView.m
//  BeeQuick
//
//  Created by 杨雷 on 2016/11/20.
//  Copyright © 2016年 six_group. All rights reserved.
//

#import "BQYLAddView.h"
#import "BQMyCarTool.h"
@interface BQYLAddView ()
@property (weak, nonatomic) IBOutlet UIButton *minusBtn;

@property (weak, nonatomic) IBOutlet UILabel *countLbael;


@end



@implementation BQYLAddView

-(void)setMinusCount:(NSInteger)minusCount
{
    _minusCount = minusCount;
    //隐藏个数为0时减号和数量Label
    _minusBtn.hidden = (minusCount == 0);
    _countLbael.hidden = (minusCount == 0);
    //数量Label
    _countLbael.text = @(minusCount).description;
    
}


#pragma mark - model 的set方法
- (void)setModel:(BQHomeGoodModel *)model
{
    _model = model;
    _countLbael.text = @(model.buyCount).description;
    
    if(model.buyCount == 0)
    {
        //隐藏个数为0时减号和数量Label
        _minusBtn.hidden = YES;
        _countLbael.hidden = YES;
    }
    else
    {
        _minusBtn.hidden = NO;
        _countLbael.hidden = NO;
    }
    
}


#pragma mark - 加号
- (IBAction)addBtn:(UIButton *)sender
{
    self.isAdd = YES;
//    self.minusCount++;
    
    self.model.Selected = YES;
    //给单例 添加一个商品
    [[BQMyCarTool shareMyCar] addGoods:self.model];
    
    //
    self.countLbael.text = @(self.model.buyCount).description;
    
    
    if(_model.buyCount == 0)
    {
        //隐藏个数为0时减号和数量Label
        _minusBtn.hidden = YES;
        _countLbael.hidden = YES;
    }
    else
    {
        _minusBtn.hidden = NO;
        _countLbael.hidden = NO;
    }

    
//    if ([_delegate respondsToSelector:@selector(minusAddView:withcount:)])
//    {
//        [_delegate minusAddView:self withcount:self.minusCount];
//    }
    
    
}
#pragma mark - 减号
- (IBAction)minusAction:(UIButton *)sender
{
    _isAdd = NO;
//    self.minusCount--;
    
    [[BQMyCarTool shareMyCar] removeGoods:self.model];
    
    self.countLbael.text = @(self.model.buyCount).description;
    
    
    if(_model.buyCount == 0)
    {
        //隐藏个数为0时减号和数量Label
        _minusBtn.hidden = YES;
        _countLbael.hidden = YES;
    }
    else
    {
        _minusBtn.hidden = NO;
        _countLbael.hidden = NO;
    }

    
//    if ([_delegate respondsToSelector:@selector(minusAddView:withcount:)])
//    {
//        [_delegate minusAddView:self withcount:self.minusCount];
//    }
}

//加载nib的类方法
+ (instancetype)minusAddView
{
    UINib *nib = [UINib nibWithNibName:@"BQYLAddView" bundle:nil];
    
    return [[nib instantiateWithOwner:nil options:nil]lastObject];
    
}



- (void)awakeFromNib
{
    [super awakeFromNib];
    
//    self.minusCount = 0;
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
